using System.Collections.Generic;
using SQLiteHelper;

namespace FileVersionManagement.Utility
{
    public class CacheManager
    {
        public static Dictionary<int, string> AppointmentType = new Dictionary<int, string>();
        public static Dictionary<int, string> AppointActionType = new Dictionary<int, string>();
        public static Dictionary<int, string> LoopMode = new Dictionary<int, string>();

        static CacheManager()
        {
            LoadData();
        }

        private static void LoadData()
        {
            var sqLite = MySqLiteFactory.GetFromPool();
            var sqLiteDataReader = sqLite.ExcuteReader("select * from AppointmentType");
            while (sqLiteDataReader.Read())
            {
                AppointmentType.Add(sqLiteDataReader.GetInt32(0), sqLiteDataReader.GetString(1));
            }
            sqLiteDataReader.Close();

            sqLiteDataReader = sqLite.ExcuteReader("select * from AppointmentAction");
            while (sqLiteDataReader.Read())
            {
                AppointActionType.Add(sqLiteDataReader.GetInt32(0), sqLiteDataReader.GetString(1));
            }
            sqLiteDataReader.Close();

            sqLiteDataReader = sqLite.ExcuteReader("select * from LoopMode");
            while (sqLiteDataReader.Read())
            {
                LoopMode.Add(sqLiteDataReader.GetInt32(2), sqLiteDataReader.GetString(1));
            }
            sqLiteDataReader.Close();
        }

        public static void ResetCache()
        {
            AppointmentType.Clear();
            AppointActionType.Clear();
            LoopMode.Clear();
            LoadData();
        }
    }
}